package view.component.tip
{
import flash.text.TextField;

import framework.view.components.Component;
import framework.view.components.tip.ITip;

/**
 * CommonTip
 * @author jliang
 *
 */
public class CommonTip extends Component implements ITip
{
	//==========================================================================
	//  Class constants
	//==========================================================================
	public static const MAX_TIP_WIDTH:Number = 240;
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function CommonTip()
	{
		super();
	}
	//==========================================================================
	//  Variables
	//==========================================================================
	protected var textPadding:Number = 0;
	
	protected var textHPadding:Number = 0;
	
	//==========================================================================
	//  Properties
	//==========================================================================
	public function get data():*
	{
		return textField ? textField.text : "";
	}
	
	public function set data(value:*):void
	{
		reset();
		
		if (textField)
		{
			textField.htmlText = value;
		}
		resize();
	}
	
	protected function get textField():TextField
	{
		return skin ? skin.label : null;
	}
	//==========================================================================
	//  Overridden methods: Component
	//==========================================================================
	override protected function get skinReference():String
	{
		return "swf.ui.CommonTipSkin";
	}
	
	override public function initialize():void
	{
		super.initialize();
		
		textPadding = textField.x;
		textHPadding = textField.y;
	}
	//==========================================================================
	//  Protected methods
	//==========================================================================
	protected function reset():void
	{
		textField.text = "";
		
		textField.width = MAX_TIP_WIDTH;
		textField.height = textField.textHeight + 6;
	}
	
	protected function resize():void
	{
		var tw:Number = textField.textWidth + 6;
		var th:Number = textField.textHeight + 6;
		
		textField.width = tw;
		textField.height = th;
		
		skin.bg.width = tw + textPadding * 2;
		skin.bg.height = th + textHPadding * 2;
		
		if(skin.top)
		{
			skin.top.width = skin.bg.width * 1.02;
		}
		
		if(skin.right)
		{
			skin.right.x = skin.bg.width - 12;
		}
	}
}
}




